package cn.jtfadmin.base.shiro.support;

import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.crypto.hash.SimpleHash;

/**
 * shiro 密码匹配及加密器
 * 通用的密码加密器<br/>
 * 使用位置 shiro 密码校验， 用户密码加密
 *
 * @author jtf
 * @since 0.0.1
 */
public class ShiroPasswordMatch {

    private static String hashAlgorithmName = "MD5";

    private static HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher(hashAlgorithmName);


    public static String encode(String str) {
        return new SimpleHash(hashedCredentialsMatcher.getHashAlgorithmName(), str, null, hashedCredentialsMatcher.getHashIterations())
                .toHex();

    }

    public static CredentialsMatcher getShiroCredentialMatch() {
        return hashedCredentialsMatcher;
    }
}
